define(['app'], function(app) {
    'use strict';

    var controller = function controller($scope,Mypbuy,GoPicture) {

		//初始化关键字
		$scope.input = new Object();
		$scope.input.id = '';
		$scope.input.goods = new Object();
		

		//加载数据
		$scope.edit_data = function() {
			$scope.input.id = "";
			if($scope.input.invoice_type3){
				if($scope.input.invoice_type1){
					$scope.input.invoice_type = 1;
				}
				else if($scope.input.invoice_type2){
					$scope.input.invoice_type = 2;
				}else{
					$scope.input.invoice_type = 3;
				}
			}
			else{
				$scope.input.invoice_type = 3;
			}
			$scope.input.goods.photo_id= "";
			$scope.input.goods.image= "";
			$scope.input.goods.brand_need= "";
			//获取轮播区启用的内容
			Mypbuy.goods_edit($scope.input.title,$scope.input.id,$scope.input.end_time,$scope.input.address_id,$scope.input.invoice_type,
					$scope.input.phone,$scope.input.memo,$scope.input.goods.name,$scope.input.goods.describe,$scope.input.goods.type_id,
					$scope.input.goods.brand_need,$scope.input.goods.brand_id,$scope.input.goods.count,$scope.input.goods.photo_id,$scope.input.goods.image,
					function(data) {
					});
		}
		//图片
		$scope.input.uploads = new Array(); //视频缩略图
        //图片移除
        $scope.ondelete = function(index) {
            $scope.input.uploads.splice(index, 1);
        };
        //动态响应
        $scope.doShowFile = function() {
            document.getElementById("upfilebutton").click();
        }
        //图片上传
        $scope.onupload = function(val) {
            var fileList = val.files;
            for(var i = 0; i < val.files.length; i++) {
                var reader = new FileReader();
                reader.readAsDataURL(fileList[i]);
                var file = fileList[i];
                reader.onload = function(e) {
                    //图片进行压缩处理
                    GoPicture.compress(file,e.target.result, 50, function(base64) {
                        $scope.$apply(function() {
                            $scope.input.uploads.push(base64);
                        });
                        val.value = "";
                    });
                }
            }
            //清空value值
            val.value = "";
        };


    }

    controller.$inject = ['$scope', 'Mypbuy','GoPicture'];

    return app.registerController("mypbuyctrl",controller);
});